package 异常处理;

/**
 * @author chihb
 * @create-time 2024/7/1 9:22
 * @description
 */
public class Test {
    public static void main(String[] args) {
//        try {
//            Age(160);
//        } catch (Exception e) {
//           e.printStackTrace();
//        }

        try {
            Age2(180);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    public static void Age(int age){
        if(age>0 && age<150){
            System.out.println("年龄合法");
        }else{
            throw new AgeIllegalRuntimeException("年龄不合法");
        }
    }

    public static void Age2(int age) throws AgellegalException{
        if(age>0 && age<150){
            System.out.println("年龄合法");
        }else{
            //throw 抛出去这个异常对象
            //throws 用在方法上，抛出方法内部的异常
            throw new AgellegalException("年龄不合法");
        }
    }
}
